﻿Imports MeoTom.Core.BLL
Imports MeoTom.Core

Partial Public Class TagUpdate
    Inherits UI.Page
    Private ReadOnly _tag As New Tags()

    Private ReadOnly _util As New Utilities.Common()

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim previousPage As String
            If Request.QueryString.ToString = vbNullString Then
                previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO"))
            Else
                previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO") & "?" & Request.QueryString.ToString())
            End If
            _util.ValidateLogin(previousPage)

            If Request.QueryString("action") = "Delete" Then
                _tag.TagID = Integer.Parse(Request.QueryString("TagID"))
                _tag.Delete()
                Response.Redirect("/mt-inside/ArticleTag.aspx", False)
            Else
                _tag.TagID = Integer.Parse(Request.QueryString("TagID"))
                _tag.GetByID()

                txtName.Text = _tag.TagName
            End If
        End If
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
        _tag.TagID = Integer.Parse(Request.QueryString("TagID"))
        _tag.TagName = _util.NoHTML(txtName.Text)
        If _tag.Update Then
            Response.Redirect("/mt-inside/ArticleTag.aspx?message=3", False)
        Else
            Response.Redirect("/mt-inside/ArticleTag.aspx?message=5", False)
        End If
    End Sub
End Class